<template>
  <div class="bind_wrap">
    <headTop :headClass="'white_header'">Account binding</headTop>
    <div class="bind_list">
      <div class="bind_item" @click="bindAli">
        <div class="left_wrap">
          <i class="iconfont icon-zhifubao"></i>
          <span>Alipay binding</span>
        </div>
        <div class="right_wrap">
          <span :class="{'has_bind': aliAccount}">{{aliAccount ? aliAccount : 'binding'}}</span>
          <i class="iconfont icon-fanhui-copy-copy"></i>
        </div>
      </div>
      <div class="bind_item" @click="bindWechat">
        <div class="left_wrap">
          <i class="iconfont icon-weixin"></i>
          <span>WeChat binding</span>
        </div>
        <div class="right_wrap">
          <span :class="{'has_bind': wechatAccount}">{{wechatAccount ? wechatAccount : 'binding'}}</span>
          <i class="iconfont icon-fanhui-copy-copy"></i>
        </div>
      </div>
      <div class="bind_item" @click="bindBankcard">
        <div class="left_wrap">
          <i class="iconfont icon-msnui-card"></i>
          <span>Bank card binding</span>
        </div>
        <div class="right_wrap">
          <span v-if="!bankName">binding</span>
          <i class="iconfont icon-fanhui-copy-copy"></i>
        </div>
      </div>
    </div>
    <div class="bankcard_wrap" v-if="bankName">
      <span class="bank_name">China · {{bankName}}</span>
      <span class="branch_name">{{branchName}}</span>
      <span class="card">{{bankcard ? bankcard.replace(/\d+(\d{4})/, '****  ****  ****  $1') : bankcard}}</span>
    </div>
  </div>
</template>

<script>
export default {
  name: 'bindList',
  data () {
    return {
      aliAccount: '',
      wechatAccount: '',
      bankName: '',
      branchName: '',
      bankcard: ''
    };
  },
  beforeMount () {
    this.getData();
  },
  methods: {
    // get data
    getData () {
      this.axios.get('index/rename/bangd').then(({data}) => {
        if (data.status === 200) {
          this.aliAccount = data.data.apliay;
          this.wechatAccount = data.data.wechat;
          if (data.data.bank) {
            this.bankName = data.data.bank.bank_name;
            this.bankcard = data.data.bank.bank_number;
            this.branchName = data.data.bank.bank_title;
          }
        } else {
          this.Toast(data.message);
        }
      });
    },
    bindAli () {
      if (this.aliAccount) {
        this.Toast('You have bound Alipay., Cannot bind again');
        return false;
      } else {
        this.$router.push('bindAlipay');
      }
    },
    bindWechat () {
      if (this.wechatAccount) {
        this.Toast('You have bound WeChat., Cannot bind again');
        return false;
      } else {
        this.$router.push('bindWechat');
      }
    },
    bindBankcard () {
      if (this.bankcard) {
        this.Toast('You have already tied the bank card., Cannot bind again');
        return false;
      } else {
        this.$router.push('bindBankcard');
      }
    }
  }
};
</script>

<style lang="scss" scoped>
  @import '../style/mixin.scss';
  .bind_wrap{
    padding-top: 108px;
    background-color: #fff;
    .bind_list{
      width: 100%;
      padding: 0 30px;
      position: relative;
      margin-bottom: 40px;
      .bind_item{
        width: 100%;
        height: 108px;
        display: flex;
        justify-content: space-between;
        border-bottom: 1px solid #e6e6e6;
        .left_wrap{
          height: 100%;
          display: flex;
          align-items: center;
          font-size: 28px;
          color: #282828;
          .iconfont{
            font-size: 54px;
            margin-right: 14px;
            &.icon-zhifubao{
              color: #1194da;
            }
            &.icon-weixin{
              color: #3cb035;
            }
            &.icon-msnui-card{
              color: #fda855;
            }
          }
        }
        .right_wrap{
          height: 100%;
          display: flex;
          align-items: center;
          font-size: 26px;
          color: $color;
          margin-right: 20px;
          .iconfont{
            font-size: 30px;
            color: #afabbd;
            margin-left: 20px;
          }
          .has_bind{
            color: #999;
          }
        }
      }
      &::before{
        display: block;
        content: '';
        width: 100%;
        height: 20px;
        background-color: #f5f5f5;
        position: absolute;
        left: 0;
        top: -20px;
      }
    }
    .bankcard_wrap{
      width: 600px;
      // height: 164px;
      margin: 0 auto;
      border-radius: 8px;
      background: linear-gradient(90deg,#fda855,#ff594b);
      padding: 30px;
      display: flex;
      flex-direction: column;
      color: #fff;
      .bank_name{
        font-size: 30px;
        margin-bottom: 12px;
      }
      .branch_name{
        font-size: 24px;
      }
      .card{
        font-size: 30px;
        text-align: right;
      }
    }
  }
</style>
